<?php
namespace app\home\Controller;
use app\home\common\Common;
use app\home\common\Interfaces;
use app\infrastructure\uri\Request;
use app\infrastructure\uri\Uri;
use think\Controller;

class Index extends Uri {
    //登录
	//1767wangmeng
	//wang7218671
	public function index(){
		if(\think\Request::instance()->isAjax()){
			//验证验证码
//			if(!captcha_check(input('code'))){
//				//验证失败
//				return  ['valid'=>2,'msg'=>'验证码错误'];
//			};
			if(empty($_POST['username'])){
				return  ['valid'=>0,'msg'=>'请输入用户名'];
			}
			if(empty($_POST['password'])){
				return  ['valid'=>0,'msg'=>'请输入密码'];
			}
			$url=Uri::HOST.Uri::ADMINUSER.input('username')."/".input('password');
			$client=new Request();
			$value = $client->getArrayData($url);
			if($value['code'] != 0){
				return  ['valid'=>0,'msg'=>'用户名或密码错误'];
			}else{
				session('username',$value['data']['name']);
				session('userid',$value['data']['id']);
               return ['valid'=>1,'msg'=>'登录成功'];
			}
		}
		 return view();
	}
    /**
	 * 退出
	 */
	public function  loginOut(){
		session(null);
		$this->redirect('home/index/index');
	}
}